package com.hfut.eeg;


import com.hfut.eeg.common.component.EEGLocalFileReader;
import com.hfut.eeg.dto.TodayErrWaves;
import com.hfut.eeg.socket.AiServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;


/**
 * @author 梁琦
 * @program: eeg
 * @Package com.hfut.eeg
 * @Description: TODO
 * @date 2019-11-04 21:26
 */

@SpringBootApplication
public class EggApplication implements CommandLineRunner {
    //今日的异常波数量
    public static TodayErrWaves todayErrWaves;
    @Autowired
    public void setTodayErrWaves(TodayErrWaves todayerrWaves){
        todayErrWaves = todayerrWaves;
    }
    //获取AiServer
    public static AiServer aiServer;

    private static EEGLocalFileReader eegLocalFileReader;
    @Autowired
    public void setAiServer(AiServer aiserver){
        aiServer = aiserver;
    }

    @Autowired
    public void setEegLocalFileReader(EEGLocalFileReader eegLocalFileReader) {
        EggApplication.eegLocalFileReader = eegLocalFileReader;
    }

    public static void setTimer(){
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0); // 控制时
        calendar.set(Calendar.MINUTE, 0);       // 控制分
        calendar.set(Calendar.SECOND, 0);       // 控制秒
        Date time = calendar.getTime();         // 得出执行任务的时间,此处为今天的00：00：00
        new Timer().schedule(todayErrWaves,time,1000*60*60*24);

    }

    @Override
    public void run(String... args) throws Exception {
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(EggApplication.class,args);
        //启动AiServer
        new Thread(aiServer).start();
        setTimer();
        //运行本地数据缓存，只在需要的时候运行，不需要请注释
        try {
            eegLocalFileReader.readerRun();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
